
package org.openeai.lite.console.actionhandlers;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.apache.log4j.Logger;
import org.openeai.lite.common.control.RouterController;
import org.openeai.lite.common.exception.OpenEAIException;
import org.openeai.lite.common.util.Constants;


@ManagedBean(name = "routerStopStartActionHandler")
@RequestScoped
public class RouterStopStartActionHandler
{

    @SuppressWarnings("unused")
    private static Logger log = Logger.getLogger(RouterStopStartActionHandler.class);

    // properties
    private String status;

    private String message;

    public String getStatus() throws OpenEAIException
    {
        if (RouterController.getInstance().isStarted())
        {
            this.status = Constants.ACTIVE;
        }
        else
        {
            this.status = Constants.INACTIVE;
        }
        return status;
    }

    public void setStatus(String status)
    {
        this.status = status;
    }

    public String getMessage()
    {
        return this.message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }

    public void start() throws OpenEAIException
    {
        RouterController.getInstance().start(null, null);
        if (RouterController.getInstance().isStarted())
        {
            status = Constants.ACTIVE;      
            setMessage("Message router started.");
        }
        else
        {
            status = Constants.INACTIVE;
            setMessage("Error starting message router!");
        }
    }

    public void stop() throws OpenEAIException
    {
        RouterController.getInstance().stop();
        if (RouterController.getInstance().isStarted())
        {
            status = Constants.ACTIVE;
            setMessage("Error stopping message router!");
        }
        else
        {
            status = Constants.INACTIVE;
            setMessage("Message router stopped.");
        }
    }
}
